export class DataUtil {
  constructor() {
  }

  /**
   *
   * @param data
   * @param options
   * @returns {any}
   */
  static arrayPick(data = [], options = {idKey: 'value', item: ''}) {
    let {idKey, item} = options || {}
    let map = new Map();
    data.forEach(row => {
      map.set(row[idKey], row);
    })

    return map.get(item);
  }

  /**
   *
   * @param data
   * @param options
   * @returns {*[]}
   */
  static arrayDistinction(data = [], options = {idKey: 'value'}) {
    let {idKey} = options || {}
    let map = new Map();
    data.forEach(item => {
      map.set(item[idKey], item);
    })
    let res = [];
    map.forEach(item => {
      res.push(item)
    })
    return res;
  }
}
